package com.projet.api;

import cn.hutool.crypto.digest.DigestUtil;

import java.util.Locale;

/**
 * 加密
 */
public class SignUtil {
    public static String appKey = "ay230601001";

    public static String secret = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAIHfLal0Ylo4I";

    /**
     * 签名
     *
     * @param tmsParam
     * @return
     */
    private static String getSign(ErpParam tmsParam) {
        String p = secret + appKey + tmsParam.getTimestamp() + secret;
        String md5Hex1 = DigestUtil.md5Hex(p).toUpperCase(Locale.ROOT);
        return md5Hex1;
    }


    /**
     * 参数
     *
     * @param data
     * @return
     */
    public static ErpParam buildPara(String data, String method) throws Exception {
        ErpParam param = new ErpParam();
        param.setTimestamp(System.currentTimeMillis());
        System.out.println(param.getTimestamp());
        param.setAppKey(appKey);
        param.setMethod(method);
        param.setData(data);
        param.setSign(getSign(param));
        return param;
    }


}
